package com.nononsenseapps.feeder.net.obs;

import com.gitee.wsl.jvm.net.server.IStatus;
import com.nononsenseapps.feeder.net.obs.model.Error;

public enum ObsStatus implements IStatus {
    SWITCH_PROTOCOL(101, "Switching Protocols"),

    OK(200, "OK"),

    SUCCESS(204,"Success"),
    OBS_405(405,true,"Your path references a directory instead of a file; this request method is valid only for updating files."),
    OBS_400(400,true,"Bad Request"),
    OBS_404(404,true,"Does not exist"),


    ACTIVE_FET_404(404,true,"File does not exist"),
    ACTIVE_PUT_400(400,true,"Incoming file could not be processed.  Make sure you have specified a reasonable file name, and make sure you have set a reasonable 'Con"),

    ACTIVE_POST_400(400,true,"Bad Request"),
    ACTIVE_POST_404(404,true,"Bad Request"),

    Vault_PUT_400(400,true,"Incoming file could not be processed.  Make sure you have specified a reasonable file name, and make sure you have set a reasonable 'Content-Type' header; if you are uploading a note, 'text/markdown' is likely the right choice.\n")

    ;

    private final int requestStatus;

    private final String description;

    private boolean jsonError;

    ObsStatus(int requestStatus, String description) {
        this(requestStatus,false,description);
    }

    ObsStatus(int requestStatus,boolean jsonOut, String description) {
        this.requestStatus = requestStatus;
        this.description = description;
        this.jsonError=jsonOut;
    }


    public static ObsStatus lookup(int requestStatus) {
        for (ObsStatus status : ObsStatus.values()) {
            if (status.getRequestStatus() == requestStatus) {
                return status;
            }
        }
        return null;
    }

    @Override
    public String getDescription() {
        if(jsonError)
            return new Error(requestStatus,description).toString();
        return "" + this.requestStatus + " " + this.description;
    }

    @Override
    public int getRequestStatus() {
        return this.requestStatus;
    }

    public boolean isJsonError(){
        return jsonError;
    }
}
